import 'babel-polyfill'
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import './config/vant'
import 'nprogress/nprogress.css';
import NProgress from 'nprogress';
import '@/assets/styles/common.less';
import Toast from '@/components/toast'
import Alert from '@/components/alert'
import Loading from '@/components/loading'
import '@/http/http.config'
import config from '@/config/config'
import VueLazyload from 'vue-lazyload'

Vue.config.productionTip = false;
Vue.prototype.$toast = Toast;
Vue.prototype.$alert = Alert;
Vue.use(Loading);


Vue.mixin(config);

Vue.use(VueLazyload, {
    preLoad: 1.3,
    error: '/static/lazy/logo.jpg',
    loading: '/static/lazy/logo.jpg',
    attempt: 1
})

router.beforeEach((to,from,next)=>{

    let obj = to.meta;
    if(obj.auth){
      NProgress.start();
      document.title = obj.name;
      next();
        // if(!Object.keys(store.state.userInfo).length){
        //     Toast.error('请注册');
        //     store.commit('SET_LOGIN_STATUS', true);
        // }else if(!Object.keys(store.state.wxInfo).length){
        //     Toast.error('请在微信中打开');
        // }else if(store.state.userInfo.status !== 1){
        //     Toast.error('该账号已经被锁定');
        // }else if(!store.state.userInfo.phone){
        //     Toast.error('请绑定手机号');
        //     store.commit('SET_LOGIN_STATUS', true);
        // }else {
        //     NProgress.start();
        //     document.title = obj.name;
        //     next();
        // }
    }else {
        NProgress.start();
        document.title = obj.name;
        next();
    }


    if(!obj.open && !store.state.token){


    }else {

    }



});

router.afterEach(transition => {
    NProgress.done();
});

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app');
